home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Ian & Stuart's Australian Mac: Not for Sale
/
Another.not.for.sale (Australia).iso
/
fade into you
/
getting there
/
Apps
/
AuthMan 1.0.8
/
AuthMan XCMD
/
authLibrary.c
next >
Wrap
Text File
|
1994-05-12
|
12KB
|
445 lines
/*
* Copyright (c) 1992-1994 Regents of The University of Michigan.
* All Rights Reserved.
*
* Permission to use, copy, modify, and distribute this software and
* its documentation for any purpose and without fee is hereby granted,
* provided that the above copyright notice appears in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation, and that the name of The University
* of Michigan not be used in advertising or publicity pertaining to
* distribution of the software without specific, written prior
* permission. This software is supplied as is without expressed or
* implied warranties of any kind.
*
* Campus Computing Sites, Sales, and Service
* The University of Michigan
* c/o Robert John Churchill
* 535 W. William Street
* Ann Arbor, Michigan
* +1-313-936-2528
* rjc@ccs.itd.umich.edu
*/
#include <Devices.h>
#include <Errors.h>
#include <Files.h>
#include <Types.h>
#ifdef THINK_C
#include <Pascal.h>
#include <Think.h>
#else
What should we include for MPW? // cause an error
#endif THINK_C
#include "authLibrary.h"
/*
Open Authentication Manager Driver
Note: if err, version undefined
*/
pascal OSErr
openAuthMan(short *refNum,short *version)
{
OSErr err;
ParamBlockRec paramBlock;
paramBlock.ioParam.ioCompletion=0L;
paramBlock.ioParam.ioNamePtr=(void *)AUTHMAN_DRVR_NAME;
paramBlock.ioParam.ioPermssn=fsCurPerm;
if (!(err=PBOpen(¶mBlock,FALSE))) {
*refNum=paramBlock.cntrlParam.ioCRefNum;
paramBlock.cntrlParam.csCode=GET_AUTH_VERSION;
if (!(err=PBControl(¶mBlock,FALSE))) {
*version=paramBlock.cntrlParam.csParam[0];
}
}
return(err);
}
/*
Return Local Kerberos realm (Pascal string)
Note: if err, realmName is empty & realmType is UNKNONW_REALM_TYPE
*/
pascal OSErr
getDefaultRealm(short refNum,Str255 *realmName,short *realmType)
{
OSErr err;
ParamBlockRec paramBlock;
*(char *)realmName=0;
*realmType=UNKNONW_REALM_TYPE;
paramBlock.cntrlParam.ioCompletion=0L;
paramBlock.cntrlParam.ioVRefNum=0;
paramBlock.cntrlParam.ioCRefNum=refNum;
paramBlock.cntrlParam.csCode=GET_LOCAL_REALM;
*((Str255 **)¶mBlock.cntrlParam.csParam[0])=realmName;
if (!(err=PBControl(¶mBlock,FALSE))) {
*realmType=paramBlock.cntrlParam.csParam[2];
}
return(err);
}
/*
Get Authentication status (has a user authenticated?)
if zero, user hasn't authenticated; if non-zero, user has
Note: if err, status undefined
*/
pascal OSErr
getAuthenticationStatus(short refNum,short *status)
{
OSErr err;
ParamBlockRec paramBlock;
short retVal=FALSE;
paramBlock.cntrlParam.ioCompletion=0L;
paramBlock.cntrlParam.ioVRefNum=0;
paramBlock.cntrlParam.ioCRefNum=refNum;
paramBlock.cntrlParam.csCode=GET_AUTH_STATUS;
if (!(err=PBStatus(¶mBlock,FALSE))) {
if (status) *status=paramBlock.cntrlParam.csParam[0];
}
return(err);
}
/*
Return name user entered (Pascal string)
Note: if err, uniqName is empty
*/
pascal OSErr
getUniqname(short refNum,Str255 *uniqName)
{
OSErr err;
ParamBlockRec paramBlock;
*(char *)uniqName=0;
paramBlock.cntrlParam.ioCompletion=0L;
paramBlock.cntrlParam.ioVRefNum=0;
paramBlock.cntrlParam.ioCRefNum=refNum;
paramBlock.cntrlParam.csCode=GET_AUTH_STATUS;
if (!(err=PBStatus(¶mBlock,FALSE))) {
if (paramBlock.cntrlParam.csParam[0]) {
paramBlock.cntrlParam.ioCompletion=0L;
paramBlock.cntrlParam.ioVRefNum=0;
paramBlock.cntrlParam.ioCRefNum=refNum;
paramBlock.cntrlParam.csCode=GET_UNIQNAME;
*((Str255 **)¶mBlock.cntrlParam.csParam[0])=uniqName;
err=PBControl(¶mBlock,FALSE);
}
else {
err=statusErr;
}
}
return(err);
}
/*
Set default user name
*/
pascal OSErr
setUniqname(short refNum,Str255 *uniqName)
{
OSErr err;
ParamBlockRec paramBlock;
paramBlock.cntrlParam.ioCompletion=0L;
paramBlock.cntrlParam.ioVRefNum=0;
paramBlock.cntrlParam.ioCRefNum=refNum;
paramBlock.cntrlParam.csCode=SET_UNIQNAME;
*((Str255 **)¶mBlock.cntrlParam.csParam[0])=uniqName;
err=PBControl(¶mBlock,FALSE);
return(err);
}
/*
Tell driver to reload internal data such as realm names,
host names, force DNR lookups to get IP numbers, etc...
Note: not currently implemented
*/
pascal OSErr
reloadDrvrInfo(short refNum)
{
OSErr err;
ParamBlockRec paramBlock;
paramBlock.cntrlParam.ioCompletion=0L;
paramBlock.cntrlParam.ioVRefNum=0;
paramBlock.cntrlParam.ioCRefNum=refNum;
paramBlock.cntrlParam.csCode=RELOAD_INFO;
err=PBControl(¶mBlock,FALSE);
return(err);
}
/*
Get Kerberos v4 ticket
if promptUserFlag is non-zero, user can be prompted
lifetimeInSecs is the # of secs ticket is valid (or INFINITE_LIFETIME)
Note: if err, ticketStorage and ticketLen are undefined
*/
pascal OSErr
getV4Ticket(short refNum,void *ticketStorage,short *ticketLen,Str255 *sName, \
Str255 *sInstance,Str255 *sRealm,long lifetimeInSecs,short promptUserFlag)
{
OSErr err;
ParamBlockRec paramBlock;
if (sName) PtoCstr((void *)sName);
if (sInstance) PtoCstr((void *)sInstance);
if (sRealm) PtoCstr((void *)sRealm);
paramBlock.cntrlParam.ioCompletion=0L;
paramBlock.cntrlParam.ioVRefNum=0;
paramBlock.cntrlParam.ioCRefNum=refNum;
paramBlock.cntrlParam.csCode=GET_V4_TICKET;
*((char **)¶mBlock.cntrlParam.csParam[0])=(void *)sName;
*((char **)¶mBlock.cntrlParam.csParam[2])=(void *)sInstance;
*((char **)¶mBlock.cntrlParam.csParam[4])=(void *)sRealm;
*((long *)¶mBlock.cntrlParam.csParam[6])=lifetimeInSecs;
paramBlock.cntrlParam.csParam[8]=promptUserFlag;
*((char **)¶mBlock.cntrlParam.csParam[9])=ticketStorage;
if (!(err=PBControl(¶mBlock,FALSE))) {
*ticketLen=paramBlock.cntrlParam.csParam[0];
}
if (sName) CtoPstr((void *)sName);
if (sInstance) CtoPstr((void *)sInstance);
if (sRealm) CtoPstr((void *)sRealm);
return(err);
}
/*
Expire Kerberos v4 ticket(s)
passing NULL instead of a string acts like a wildcard
ex: sName=NULL, sInstance=NULL, sRealm="\pUMICH.EDU"
deletes all UMICH.EDU realm tickets
Note: err=paramErr if any tickets exist in ticket queue and
parameters passed in matched none of them
*/
pascal OSErr
expireV4Ticket(short refNum,Str255 *sName,Str255 *sInstance,Str255 *sRealm)
{
OSErr err;
ParamBlockRec paramBlock;
if (sName) PtoCstr((void *)sName);
if (sInstance) PtoCstr((void *)sInstance);
if (sRealm) PtoCstr((void *)sRealm);
paramBlock.cntrlParam.ioCompletion=0L;
paramBlock.cntrlParam.ioVRefNum=0;
paramBlock.cntrlParam.ioCRefNum=refNum;
paramBlock.cntrlParam.csCode=EXPIRE_V4_TICKET;
*((char **)¶mBlock.cntrlParam.csParam[0])=(void *)sName;
*((char **)¶mBlock.cntrlParam.csParam[2])=(void *)sInstance;
*((char **)¶mBlock.cntrlParam.csParam[4])=(void *)sRealm;
err=PBControl(¶mBlock,FALSE);
if (sName) CtoPstr((void *)sName);
if (sInstance) CtoPstr((void *)sInstance);
if (sRealm) CtoPstr((void *)sRealm);
return(err);
}
/*
get Kerberos v4 ticket info from cache
ticketNum range: 0 to n-1 (given n tickets)
returns paramErr if ticketNum out of range
Note: if err, strings and dates are undefined
*/
pascal OSErr
getV4TicketNinfo(short refNum,short ticketNum,_V4ticketInfo *theTicketInfo)
{
OSErr err;
ParamBlockRec paramBlock;
paramBlock.cntrlParam.ioCompletion=0L;
paramBlock.cntrlParam.ioVRefNum=0;
paramBlock.cntrlParam.ioCRefNum=refNum;
paramBlock.cntrlParam.csCode=GET_V4_TICKET_N_INFO;
paramBlock.cntrlParam.csParam[0]=ticketNum;
*((_V4ticketInfo **)¶mBlock.cntrlParam.csParam[1])=(void *)theTicketInfo;
err=PBControl(¶mBlock,FALSE);
CtoPstr((void *)theTicketInfo->sName);
CtoPstr((void *)theTicketInfo->sInstance);
CtoPstr((void *)theTicketInfo->sRealm);
CtoPstr((void *)theTicketInfo->pName);
CtoPstr((void *)theTicketInfo->pInstance);
CtoPstr((void *)theTicketInfo->pRealm);
return(err);
}
/*
get Kerberos realm info from cache
realm range: 0 to n-1 (given n realms)
returns paramErr if realmNum out of range
Note: if err, realmName, AFSFlag, and numHosts are undefined
*/
pascal OSErr
getRealmNinfo(short refNum,short realmNum,Str255 *realmName,short *AFSflag,short *numHosts)
{
OSErr err;
ParamBlockRec paramBlock;
paramBlock.cntrlParam.ioCompletion=0L;
paramBlock.cntrlParam.ioVRefNum=0;
paramBlock.cntrlParam.ioCRefNum=refNum;
paramBlock.cntrlParam.csCode=GET_REALM_N_INFO;
paramBlock.cntrlParam.csParam[0]=realmNum;
*((char **)&(paramBlock.cntrlParam.csParam[1]))=(char *)realmName;
if (!(err=PBControl(¶mBlock,FALSE))) {
if (realmName) CtoPstr((void *)realmName);
if (AFSflag) *AFSflag=paramBlock.cntrlParam.csParam[3];
if (numHosts) *numHosts=paramBlock.cntrlParam.csParam[4];
}
return(err);
}
/*
get host service for a given Kerberos realm
host range: 0 to n-1 (given n hosts for given realm)
returns paramErr if index out of range
Note: if err, hostName is undefined
*/
pascal OSErr
getRealmHostNinfo(short refNum,short realmNum,short hostNum,Str255 *hostName,short *portNum)
{
OSErr err;
ParamBlockRec paramBlock;
paramBlock.cntrlParam.ioCompletion=0L;
paramBlock.cntrlParam.ioVRefNum=0;
paramBlock.cntrlParam.ioCRefNum=refNum;
paramBlock.cntrlParam.csCode=GET_REALM_HOST_N_INFO;
paramBlock.cntrlParam.csParam[0]=realmNum;
paramBlock.cntrlParam.csParam[1]=hostNum;
*((char **)&(paramBlock.cntrlParam.csParam[2]))=(char *)hostName;
if (!(err=PBControl(¶mBlock,FALSE))) {
if (hostName) CtoPstr((void *)hostName);
if (portNum) *portNum=paramBlock.cntrlParam.csParam[4];
}
return(err);
}
/*
Encrypt or Decrypt blocks of memory w/DES
when operation is DES_PCBC-based, buffer data and bufferLen must be a 8-byte multiple
when operation is DES_ECB-based, buffer data and bufferLen must be 8 bytes
*/
pascal OSErr
doDES(short refNum,short operation,void *sessionKey,void *buffer,long bufferLen)
{
OSErr err;
ParamBlockRec paramBlock;
paramBlock.cntrlParam.ioCompletion=0L;
paramBlock.cntrlParam.ioVRefNum=0;
paramBlock.cntrlParam.ioCRefNum=refNum;
paramBlock.cntrlParam.csCode=DES_FUNCTIONS;
paramBlock.cntrlParam.csParam[0]=operation;
*((char **)&(paramBlock.cntrlParam.csParam[1]))=sessionKey;
*((char **)&(paramBlock.cntrlParam.csParam[3]))=buffer;
*((long *)&(paramBlock.cntrlParam.csParam[5]))=bufferLen;
err=PBControl(¶mBlock,FALSE);
return(err);
}
/*
Set new Password for user
Note: pName/pInstance/pRealm parameters are suggested
default values for when the password changing
dialog comes up
*/
pascal OSErr
setV4Password(short refNum,Str255 *pName,Str255 *pInstance,Str255 *pRealm)
{
OSErr err;
ParamBlockRec paramBlock;
paramBlock.cntrlParam.ioCompletion=0L;
paramBlock.cntrlParam.ioVRefNum=0;
paramBlock.cntrlParam.ioCRefNum=refNum;
paramBlock.cntrlParam.csCode=SET_V4_PASSWORD;
*((char **)&(paramBlock.cntrlParam.csParam[0]))=(char *)pName;
*((char **)&(paramBlock.cntrlParam.csParam[2]))=(char *)pInstance;
*((char **)&(paramBlock.cntrlParam.csParam[4]))=(char *)pRealm;
err=PBControl(¶mBlock,FALSE);
return(err);
}
/*
Register/Deregister for callback messages from AuthMan
Note: if used by an application, the callback must be unregistered
before the application exits
when callbackRtn is actually called, it may not in turn make
calls to AuthMan as AuthMan is "busy" and a LOCK condition
would occur
the callbackRtn must be in a locked, non-purgeable segment of code
the callbackRtn should always return noErr unless indicated as
being allowed for a given message
*/
pascal OSErr
doMsgCallback(short refNum,short callbackOperation,doAuthMsgCallbackProc callbackRtn,long callbackMiscData,long userData)
{
OSErr err;
ParamBlockRec paramBlock;
paramBlock.cntrlParam.ioCompletion=0L;
paramBlock.cntrlParam.ioVRefNum=0;
paramBlock.cntrlParam.ioCRefNum=refNum;
paramBlock.cntrlParam.csCode=AUTH_MSG_CALLBACK;
paramBlock.cntrlParam.csParam[0]=callbackOperation;
*((doAuthMsgCallbackProc **)&(paramBlock.cntrlParam.csParam[1]))=callbackRtn;
*((long *)&(paramBlock.cntrlParam.csParam[3]))=callbackMiscData;
*((long *)&(paramBlock.cntrlParam.csParam[5]))=userData;
err=PBControl(¶mBlock,FALSE);
return(err);
}